package com.xiaoyao.common.rest;

import com.xiaoyao.common.pojo.User;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

public abstract class BaseApi {

    public User getPrincipal(){
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if(principal instanceof UserDetails){
            return (User)principal;
        }else{
            return User.of(String.valueOf(principal));
        }
    }
}
